// pages/newBindPhone/newBindPhone.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    namevalue:'',
    phonevalue:'',
    addressvalue:'',
  },
   
  inname:function(e){
    this.setData({
      namevalue:e.detail.value
    })
  },
  inphone: function (e) {
    this.setData({
      phonevalue: e.detail.value
    })
  },
  inaddress: function (e) {
    this.setData({
      addressvalue: e.detail.value
    })
  },
  formSubmit:function(e){
   let formData = e.detail.value;
   var verify_phone = formData.userphone
   var verify_name = formData.username
   var verify_address = formData.useradress
   var warn =''
   var flag = false
   var that = this
   if(verify_phone == ''){
     warn = '请输入手机号不能为空'
   } else if (!(/^1(3|4|5|7|8)\d{9}$/.test(verify_phone))){
     warn = "输入的手机格式不正确"
   }else{
     flag = true
   }
   if(flag==false){
     wx.showModal({
       title: '提示',
       content: warn,
     })
   }
   

   wx.request({
     url: app.globalData.directory + 'api/v2/user/receiveVerifyInfo',
     method:"POST",
     data: { verify_name: verify_name, verify_phone: verify_phone, verify_address: verify_address},
     
     header:{
       'content-type': 'application/json', // 默认值
       'token': wx.getStorageSync('token')
     },
     success:function(res){
       console.log(res,'13213131')
       if(res.data.status=='ok'){
         wx.showToast({
           title: "绑定成功",
           icon: 'success',
           duration: 2000,
         })
         setTimeout(function(){
           wx.navigateBack({

           })
         },3000)
             
       }else{
         wx.showModal({
           title: '提示',
           content: res.data.msg,
         })
       }
     }
   })

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})